package com.sinodata.bsm.cicp.collector.was6;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class WasValueBuffer {

    private static WasValueBuffer instance = new WasValueBuffer();

    private WasValueBuffer() {
    }

    public static WasValueBuffer getInstance() {
        return instance;
    }

    private Map<String, WasCollectTask> taskCache = new HashMap<String, WasCollectTask>();
    private Object lock = new Object();

    public String getXml(String ip, String port, String module) {
        String key = ip + "#" + port + "#" + module;
        WasCollectTask task = null;
        if ((task = taskCache.get(key)) == null) {
            synchronized (lock) {
                task = new WasCollectTask(ip, port, module);
                taskCache.put(key, task);
            }
        }
        if (task.isActive()) {
            return task.getResult();
        }
        return task.getXml();
    }

}
